<?php

namespace app\admin\controller\general;

use app\common\controller\Backend;

/**
 * 友情链接管理
 *
 * @icon   fa fa-circle-o
 * @remark 管理前端显示的友情链接
 */
class Link extends Backend
{

    /**
     * @var \app\common\model\Link
     */
    protected $relationSearch = true;
    protected $searchFields = 'id,name,url';
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Link');
    }


    /**
     * 添加
     */
    public function add()
    {
        if ($this->request->isPost()) {
            $this->token();
        }
        return parent::add();
    }
    /**
     * 编辑
     */
    public function edit($ids = null)
    {
        if ($this->request->isPost()) {
            $this->token();
        }
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        return parent::edit($ids);
    }

    /**
     * 删除
     * @param array $ids
     */
    public function del($ids = "")
    {
        if (!$this->request->isPost()) {
            $this->error(__("Invalid parameters"));
        }
        $ids = $ids ? $ids : $this->request->post("ids");
        if ($ids) {
            $attachmentlist = $this->model->where('id', 'in', $ids)->delete();
            $this->success();
        }
        $this->error(__('Parameter %s can not be empty', 'ids'));
    }

}
